package com.tydic.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tydic.system.domain.SysConfig;
import com.tydic.system.domain.bo.QuerySysConfigBo;
import com.tydic.system.domain.vo.SysConfigVo;
import com.tydic.system.mapper.SysConfigMapper;
import com.tydic.system.service.ISysConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 参数配置 服务层实现
 *
 * @author Lion Li
 */
@RequiredArgsConstructor
@Service
public class SysConfigServiceImpl implements ISysConfigService {

    private final SysConfigMapper baseMapper;


    @Override
    public Page<SysConfigVo> queryPage(QuerySysConfigBo bo) {
        return baseMapper.selectVoPage(bo.build(), queryWrapper(BeanUtil.toBean(bo, SysConfig.class)));
    }

    private LambdaQueryWrapper<SysConfig> queryWrapper(SysConfig sysConfig) {
        LambdaQueryWrapper<SysConfig> lqw = Wrappers.lambdaQuery();
        lqw.like(CharSequenceUtil.isNotBlank(sysConfig.getConfigKey()), SysConfig::getConfigKey, sysConfig.getConfigKey());
        lqw.like(CharSequenceUtil.isNotBlank(sysConfig.getConfigName()), SysConfig::getConfigName, sysConfig.getConfigName());
        lqw.like(CharSequenceUtil.isNotBlank(sysConfig.getConfigValue()), SysConfig::getConfigValue, sysConfig.getConfigValue());
        return lqw;
    }

    @Override
    public SysConfigVo getById(String id) {
        return baseMapper.selectVoById(id);
    }
}
